let Dialog={};
import RxMapDialog from "../components/RxMapDialog/RxMapDialog.vue/";
// #ifdef H5
import BpmImageView from '../views/modules/bpm/BpmImageView/BpmImageView'
// #endif
import Util from "./Util.js";
export default Dialog;

/**
 * 打开用户选择对话框
 * @param {Object} params {
 *  data:{
 *      value:[{}],
        single:true,
        dimIds:"1",
        //租户ID可以不填
        tenantId:"1",
        //显示维度
        organization:false
 *  },
 *  curVm:当前vue实例

   }
 * @param {Function} callback 回调方法.
 */
Dialog.openUserDialog=function (params,callback){
    if(params.data && params.data.initUsers){
        params.data['value'] =params.data.initUsers;
        delete params.data.initUsers
    }
    let eventName = 'openUserDialog_'+Util.randomId();
    uni.setStorageSync('openUserParams',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/components/RxUserDialog'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
/**
 * 弹窗数据部门
 * @param params
 * data:{
 *
 * }
 * @param callback 回调方法
 */
Dialog.openGroupDialog=function (params,callback){
    let eventName = 'openGroupDialog_'+Util.randomId();
    uni.setStorageSync('openGroupParams',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/components/RxGroupDialog/RxGroupDialog'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}

/**
 * 弹窗打开地图数据
 * @param params
 * data:{
 *
 * }
 * @param callback 回调方法
 */
Dialog.openMapDialog=function (params,callback){
    let conf={
        component:RxMapDialog,
        ...params
    }
    Util.open(conf,callback);
}

/**
 * 打开对话框
 * @param {Object} params {
 *     data:{
 *          single:false,
 *          alias:"",
 *          initData:{
 *               keyField:"ID_",
 *               selected:["1783497147321196546","1783497365437587457"]
 *           }
 *      },
 *      curVm:当前vue实例
 * }
 * @param {Function} callback 回调函数此函数有一个返回参数
 * (data)=>{}
 */
Dialog.openDialog=function (params,callback){
    let eventName = 'listDialog_'+Util.randomId();
    uni.setStorageSync('openListParams',{params:params.data,eventName:eventName})
    let appId = Util.getAppId(params.curVm)
    uni.navigateTo({
        url:'/views/modules/form/formBoList/FormBoListDialog?appId='+appId
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}

Dialog.openCity=function (params,callback){
    let eventName = 'openCity_'+Util.randomId();
    uni.setStorageSync('openCity',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/views/modules/components/MCity/cityIndexList/index'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
/*
打开流程图
 */
Dialog.openBpmImageView=function (params,callback){
    // #ifdef H5
    let conf={
        component:BpmImageView,
        ...params
    }
    Util.open(conf,callback);
    // #endif
    // #ifdef APP-PLUS
    uni.navigateTo({
        url:"/views/modules/bpm/BpmImageView/BpmImageApp?defId="+params.data.defId
    })
    // #endif
}

/**
 * 打开表单方案
 */
Dialog.openForm=function (params,callback){
    let eventName = 'openFormDialog_'+Util.randomId();
    uni.setStorageSync('openFormParams',{params:params.data,eventName:eventName})
    let appId =params.data.paramsControl.appId
    let url ='/views/modules/form/customForm/FormSolutionShow/FormSolutionComponentDialog'
    url= appId?url+'?appId='+appId:url;
    uni.navigateTo({
        url:url
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}

Dialog.RxSignDialog=function (params,callback){
    let eventName = 'RxSignDialog_'+Util.randomId();
    uni.setStorageSync('RxSignDialog',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/components/RxSignDialog'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
/*
选择签名
 */
Dialog.MSignSelectDialog=function (params,callback){
    let eventName = 'MSignSelectDialog_'+Util.randomId();
    uni.setStorageSync('MSignSelectDialog',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/views/modules/components/MSignature/MSignSelectDialog'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
/*
盖章
 */
Dialog.MsealDialog=function (params,callback){
    let eventName = 'MsealDialog_'+Util.randomId();
    uni.setStorageSync('MsealDialog',{params:params.data,eventName:eventName})
    uni.navigateTo({
        url:'/views/modules/components/MSeal/MsealDialog'
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
/*
打开页面定制
 */
Dialog.openCustomPage = function (params,callback){
    let eventName = 'openCustomPage_'+Util.randomId();
    uni.setStorageSync('openCustomPage',{params:params.params,eventName:eventName})
    let paramsObj = {
        alias: params.alias,
        title: params.title,
        params:params.params
    }
    uni.navigateTo({
        url: '/views/modules/form/FormCustomView/FormCustomView?params=' + JSON.stringify(paramsObj) + '&appId=' + params.appId
    })
    uni.$on(eventName,(data)=>{
        if(callback){
            callback(data)
        }
        uni.$off(eventName)
    })
}
